package com.bdqn;

public class TextPaper implements Paper{
    private int charPerLine = 16;
    private int linePerPage = 5;
    private String context = "";
    private int posX = 0;
    private int posY = 0;
    private int posP = 1;


    @Override
    public String getContent() {
        String ret = this.context;
        // 补齐本页空行，并显示页码
        if (!(posX == 0 && posY == 0)){
            int count = linePerPage - posY;
            for (int i = 0; i < count; i++) {
                ret += Paper.newline;
            }
            ret += "== 第" + posP + "页 ==";
        }
        return ret;
    }

    @Override
    public void putInChar(char c) {
        context +=c;
        ++posX;
        if (posX == charPerLine){
            context += Paper.newline;
            posX = 0;
            ++posX;
        }
        if (posY == linePerPage){
            context += "== 第" + posP + "页 ==";
            context += Paper.newline + Paper.newline;
            posY = 0;
            ++posP;
        }
    }

    public void setCharPerLine(int charPerLine){
        this.charPerLine = charPerLine;
    }

    public void setLinePerPage(int linePerPage){
        this.linePerPage = linePerPage;
    }


}
